package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONArray;
import org.json.JSONObject;

import dao.ProfileDAO;

import model.Employee;
import model.JobRes;
import model.Project;

/**
 * Servlet implementation class profileAcion
 */
public class profileAcion extends HttpServlet {
	private static final long serialVersionUID = 1L;
	ProfileDAO pDao;
	JSONObject json = new JSONObject();
	
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public profileAcion() {
        super();
        // TODO Auto-generated constructor stub
    }

    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee director = null;
		try {
			pDao = new ProfileDAO();
			if(!session.isNew()) {
				Employee em = (Employee) session.getAttribute("person");
				
				if(em.getProject().getProjectId() == 0 || em.getTitle().getTitleId() == 6) {
					String str = "NO director";
					request.setAttribute("director", str);
				}
				else {
					director = pDao.getProjectDirector(em.getProject().getProjectId());
					request.setAttribute("director", director.getFullname());
				}
				RequestDispatcher dispatcher = request.getRequestDispatcher("profile.jsp");
				dispatcher.include(request, response);
			}
			else {
				response.sendRedirect("gui.jsp");
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
